-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.java
33 lines (26 loc) · 856 Bytes
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.Scanner;
public class PalindromeCheck {
// Function to check if a string is a palindrome
static boolean isPalindrome(String str) {
int start = 0, end = str.length() - 1;
while (start < end) {
if (str.charAt(start) != str.charAt(end)) {
return false; // Not a palindrome
}
start++;
end--;
}
return true; // Palindrome
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a string: ");
String str = scanner.nextLine();
if (isPalindrome(str)) {
System.out.println("The string is a palindrome.");
} else {
System.out.println("The string is not a palindrome.");
}
scanner.close();
}
}